# from http import HTTPStatus
# from dashscope import Generation
# import dashscope
#
# dashscope.api_key = 'LTAI5tMHkCm8Dt5HoKJFeChb'
#
#
# def multi_round():
#     messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},
#                 {'role': 'user', 'content': '如何做西红柿炖牛腩？'}]
#     response = Generation.call(model="qwen-turbo",
#                                messages=messages,
#                                # 将输出设置为"message"格式
#                                result_format='message')
#     if response.status_code == HTTPStatus.OK:
#         print(response)
#         # 将assistant的回复添加到messages列表中
#         messages.append({'role': response.output.choices[0]['message']['role'],
#                          'content': response.output.choices[0]['message']['content']})
#     else:
#         print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
#             response.request_id, response.status_code,
#             response.code, response.message
#         ))
#         # 如果响应失败，将最后一条user message从messages列表里删除，确保user/assistant消息交替出现
#         messages = messages[:-1]
#     # 将新一轮的user问题添加到messages列表中
#     messages.append({'role': 'user', 'content': '不放糖可以吗？'})
#     # 进行第二轮模型的响应
#     response = Generation.call(model="qwen-turbo",
#                                messages=messages,
#                                result_format='message',  # 将输出设置为"message"格式
#                                )
#     if response.status_code == HTTPStatus.OK:
#         print(response)
#     else:
#         print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
#             response.request_id, response.status_code,
#             response.code, response.message
#         ))
#
#
# if __name__ == '__main__':
#     multi_round()



# from langchain_community.llms import Tongyi
#
# # 假设 Tongyi 需要一个 API 密钥作为参数，这取决于具体的实现
# # 在这里，你需要将 'YOUR_API_KEY' 替换为你从通义千问获取的API密钥
# api_key = 'LTAI5t8n7bPx5nBQmvP5MW2u'
#
# # 初始化 Tongyi 对象
# tongyi = Tongyi(api_key)
#
# # 调用 Tongyi 的 invoke 方法，传入你的查询
# query = "雷军是谁"
# result = tongyi.invoke(query)
#
# # 打印结果
# print(result)






